<template>
	<view class='container bg-w'>
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="维护记录">
				<template slot='left'>
					<view class="flex width-100">
						<i class='iconfont iconfanhui' @click='goBack()'></i>
					</view>
				</template>
				<template slot='right'>
					<i class='iconfont iconshaixuan right-i' @click="open"></i>
				</template>
			</uni-nav-bar>
		</view>
		<view class="position-r-top">
			<uni-search-bar :radius="100" @confirm="searchName" @cancel='cancelName' placeholder='请输入项目名称,单位名称,维护人员'></uni-search-bar>
			<view class="buildList" v-if="productData.length > 0">
				<uni-list>
				    <uni-list-item v-for="(item,index) in productData" direction="column" :key="index" :to="'/pages/Application/MaintainAudit/MaintainRecord/RecordDetail/RecordDetail?maintainTaskId='+item.maintainTaskId">
						<template slot='body'>
							<view class="main-center">
								<view class="buildList-body">
									<view class="color-6 flex algin-i-c"> <view>{{item.taskName}}</view><text class="txtCut1 color-af" style="text-align: right;">{{item.auditTime.substr(0,19)}}</text></view>
									<view class="color-af flex algin-i-c"> <view>维护单位：</view><text class="wid-60 txtCut1">{{item.orgName}}</text><text class="wid-20 txtCut1"></text></view>
									<view class="color-af flex algin-i-c"> <view>维护人员：</view><text class="wid-60 txtCut1">{{item.auditUserName}}</text><text class="wid-20 txtCut1" style="text-align: right;">{{item.maintainResultDesc}}</text></view>
								</view>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
			</view>
			<view class="nodata" v-else>
				<text>暂无数据</text>
			</view>
		</view>
		<view class="">
			<uni-popup ref="popup" type="bottom">
				<view class="screen-popup">
					<view class="screen-popup-title flex flex-between">
						<text class="margin-l-10"> 筛选 </text>
						<view class="flex border-left">
							<text @click="close()">取消</text>
							<text @click="screenSubmit()">确认</text>
						</view>
					</view>
					<view class="screen-popup-body">
						<view class="">
							<text>日期</text>
						</view>
						<view class="date-box">
							<view class="date_item">
								<dyDatePicker placeholder="起始日期" :childValue="startDate" :minSelect="statr_minSelect" :maxSelect="statr_maxSelect"
								 :iconshow="false" @getData="getFromData"></dyDatePicker>
							</view>
							<view class="filter_inputline">~</view>
							<view class="date_item">
								<dyDatePicker placeholder="结束日期" :minSelect="end_minSelect" :childValue="endDate" :maxSelect="end_maxSelect" :iconshow="false"
								 @getData="getToData"></dyDatePicker>
							</view>
						</view>
						<view class="">
							<text>结果</text>
							<uni-group>
								<uni-data-checkbox mode="tag" v-model="result" :localdata="resultData"></uni-data-checkbox>
							</uni-group>
						</view>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import {getRecord } from "@/common/api/MaintainAudit.js"
	import dyDatePicker from '@/components/dy-Date/dy-Date.vue'
	export default{
		components: {
			dyDatePicker
		},
		data(){
			return{
				productData: [],
				result:'',
				resultData:[{value:1,text:'优秀'},{value:2,text:'良好'},{value:3,text:'一般'},{value:4,text:'较差'}],
				page: {
					pageNo: 1,
					pageSize: 20,
					keyword:'',
				},
				totalPage:0,
				statr_minSelect: '1900/01/01',//开始日期最小可选日期
				statr_maxSelect: '2050/12/31',//开始日期最打可选日期
				end_minSelect: '1900/01/01',//结束日期最小可选日期
				end_maxSelect: '2050/12/31',//结束日期最大可选日期
				startDate: '',//开始日期
				endDate: '',//结束日期
				
			}
		},
		onLoad() {
			this.loadProductList();
		},
		methods:{
			loadProductList(){
				getRecord(this.page).then(res => {
					if(res.code == 20000){
						if(res.data){
							this.totalPage = res.data.pages;
							this.productData = this.productData.concat(res.data.records)
						}
					}
				})
			},
			bindDateChange(e) {
				this.date = e.detail.value
			},
			bindDateChange1(e) {
				this.date1 = e.detail.value
			},
			searchName(e){
				this.productData = [];
				this.page.keyword = e.value
				getRecord(this.page).then(res => {
					if(res.data){
						this.productData = res.data.records
					}
				})
			},
			cancelName(){
				this.productData = [];
				this.page.pageNo = 1;
				this.page.keyword = null;
				getRecord(this.page).then(res => {
					if(res.data){
						this.productData = res.data.records
					}
				})
				
			},
			open(){
				this.$refs.popup.open()
			},
			// 开始时间
			getFromData(time) {
				this.end_minSelect = time
				this.startDate = time
				console.log('1',this.end_minSelect)
				console.log(this.startDate)
			},
			// 截止时间
			getToData(time) {
				this.statr_maxSelect = time
				this.endDate = time
				console.log(this.statr_maxSelect)
				console.log(this.endDate)
			},
			close(){
				this.$refs.popup.close()
			},
			screenSubmit(){
				 this.productData = [];
				 this.result? this.page.resultType=this.result : delete this.page.resultType;
				 this.endDate? this.page.endTime= this.endDate.replace(/-/g,"/") : delete this.page.endTime;
				 this.startDate? this.page.startTime=this.startDate.replace(/-/g,"/") :delete this.page.startTime;
				 this.loadProductList();
				 this.close();
			},
			onReachBottom() { //上拉加载更多
				this.page.pageNo++
				if (this.page.pageNo <= this.totalPage) {
					this.loadProductList();
				}
			},
			onPullDownRefresh(){//下拉刷新
				this.page.pageNo = 1;
				this.productData = [];
				this.loadProductList();
				setTimeout(function () {
						uni.stopPullDownRefresh();
				}, 1000);
			},
		}
	}
</script>

<style lang="less" scoped>
	.screen-popup{
		background-color: #fff;
		min-height: 600rpx;
		.screen-popup-title{
			background-color: #f2f2f2;
			height: 100rpx;
			line-height: 100rpx;
			color: #666;
			>view{
				text{
					display: block;
					padding: 0 40rpx;
					line-height: 100rpx;
				}
				text:last-child{
					background-color: #09AAE9;
					color: #fff;
				}
			}
		}
	}
	.screen-popup-body{
		/deep/ .is-tag-checked{
			border-color: #09AAE9;
			background-color: #09AAE9;
		}
		/deep/ .uni-group__content{
			padding: 0 30rpx;
		}
		/deep/.checklist-group{
			display: flex;
			justify-content: space-between;
		}
		/deep/ .is-tag{
			padding: 10rpx 0;
			width: 22%;
			box-sizing: border-box;
			margin-right: 0;
			
		}
		/deep/ .checklist-text{display: block;width: 100%;text-align: center;}
		>view{
			text{
				display: block;
				margin-top: 20rpx;
				margin-left: 3%;
				color: #09AAE9;
			}
		}
		.date-box{
			display: flex;
			justify-content: center;
			align-items: center;
			.date_item {
				width: 300rpx;
				overflow: hidden;
				display: inline-block;
				text-align: center;
				height: 72rpx;
				line-height: 72rpx;
				input {
					height: 72rpx;
					.uni-input-placeholder {
						color: #b5b8c2;
					}
				}
			}
		}
	}
	.buildList{
		.main-center{
			display: flex;
			align-items: center;
		}
		.buildList-body{
			width: 100%;
			>view:first-child{
				margin-bottom: 0 !important;
				justify-content: space-between;
			}
		}
	}
</style>
